const fs = require('fs');
const path = require('path');
const { createCanvas } = require('canvas');

const iconsDir = path.join(__dirname, '../assets/images/icons');
if (!fs.existsSync(iconsDir)) {
  fs.mkdirSync(iconsDir, { recursive: true });
}

const icons = [
  { name: 'funeral-urn', color: '#D4A76A', text: '骨' },
  { name: 'burial-clothes', color: '#7986CB', text: '衣' },
  { name: 'funeral-flowers', color: '#81C784', text: '花' },
  { name: 'memorial-items', color: '#FF8A65', text: '品' },
  { name: 'memorial', color: '#4DB6AC', text: '念' },
  { name: 'legal', color: '#4FC3F7', text: '法' },
  { name: 'transport', color: '#FFD54F', text: '运' }
];

function createIconPng(name, color, text) {
  const size = 96;
  const canvas = createCanvas(size, size);
  const ctx = canvas.getContext('2d');

  // 背景圆
  ctx.beginPath();
  ctx.arc(size / 2, size / 2, size / 2, 0, Math.PI * 2);
  ctx.fillStyle = color;
  ctx.fill();

  // 文字
  ctx.font = 'bold 48px Arial';
  ctx.fillStyle = '#fff';
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';
  ctx.fillText(text, size / 2, size / 2);

  const buffer = canvas.toBuffer('image/png');
  fs.writeFileSync(path.join(iconsDir, `${name}.png`), buffer);
  console.log('生成图标:', name + '.png');
}

icons.forEach(icon => {
  createIconPng(icon.name, icon.color, icon.text);
});

console.log('全部分类/服务图标已生成！'); 